﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BUS.DAL;

namespace BUS
{
    public class KhachHangBUS
    {
        #region PROPERTIES
        public int ID { get; set; }
        public string MaKhachHang { get; set; }
        public string HoTen { get; set; }
        public string SoDienThoai { get; set; }
        public string DiaChi { get; set; }
        public string CMND { get; set; }
        public string Email { get; set; }

        #endregion

        public void Add()
        {
            this.ID = KhachHangDAL.Insert(this);
        }

        public static string GetNextID()
        {
            string lastID = KhachHangDAL.GetLastID();
            const string prefixID = "KH";

            int NextID = int.Parse(lastID.Remove(0, prefixID.Length)) + 1;
            int lengthNumberID = lastID.Length - prefixID.Length;
            string zeroNumber = "";

            for (int i = 1; i <= lengthNumberID; i++)
            {
                if (NextID < Math.Pow(10, i))
                {
                    for (int j = 1; j <= lengthNumberID - i; i++)
                    {
                        zeroNumber += "0";
                    }
                    return prefixID + zeroNumber + NextID.ToString();
                }
            }
            return prefixID + NextID.ToString();

        }
    }

}
